//index.js
//获取应用实例
const app = getApp()
var utils = require('../../utils/util.js');
Page({
  /**
   * 页面的初始数据
   */
  data: {
    swiper: {},
    goods: {}
  },
  onGoodsTap: function (e) {
    var goodsId = e.currentTarget.dataset.goodsId;
    wx.navigateTo({
      url: 'goods-detail/goods-detail?id=' + goodsId,
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var goodsListUrl = app.globalData.ydnBase + '/index.php/Weshop/SApi/index/key/2sdfdd332342341dddff46e189670/m/getGoodsList/wid/39/sign/'+app.globalData.sign;
    var swiperUrl = app.globalData.ydnBase + '/index.php/Weshop/SApi/index/key/2sdfdd332342341dddff46e189670/m/getSlideshow/wid/39/type/1/sign/' + app.globalData.sign;
    utils.http(swiperUrl, this.processSwiper);
    utils.http(goodsListUrl, this.processGoodsData);

  },
  processSwiper: function (swiperData) {
    var swiper = []
    swiperData.datas.forEach(function (item, index) {
      var temp = {
        imgUrl: item.img,
        index: index
      }
      swiper.push(temp)
    })
    this.setData({
      swiper: swiper
    })
  },
  processGoodsData: function (goodsData) {
    var goods = [];
    goodsData.datas.forEach(function (item) {
      var temp = {
        goodsId: item.goods_id,
        imgUrl: item.original_img,
        name: item.goods_name,
        price: item.shop_price,
        viewCount: item.view_count,
        showViewCount: item.show_view_count
      }
      goods.push(temp)
    })
    this.setData({
      goods: goods
    })
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})
